﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace win1
{
    class DataBase
    {
        private static string connStr = "Data Source=.\\MSSQLSERVER3;Initial Catalog=SecondHandCarDB;Persist Security Info=True;database=Demo;User ID=sa;Password=root";
        public static SqlConnection conn = new SqlConnection(connStr);
        public static DataSet b = new DataSet();

        //查询方法，有返回语句
        public static DataTable ExecutQ(string sql, string CarName)
        {
            SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
            adapter.Fill(b, CarName);
            return b.Tables[CarName];
        }
        //增，删，改
        public static int ExecuteU(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            int rowCount = cmd.ExecuteNonQuery();
            conn.Close();
            return rowCount;
        }

    }
}
